//
//  FadeInOutViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class FadeInOutViewController: UIViewController {

    @IBOutlet var imageView_cat: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.title = "淡入淡出"
        
        setNavigationItem()
       // self.navigationItem.rightBarButtonItem.tintColor = UIColor.blackColor()

        
    }
    
    func setNavigationItem(){
        var rigthBarButtonItem = UIBarButtonItem(title: "淡出", style: UIBarButtonItemStyle.Bordered, target: self, action: "fadeOut")
        self.navigationItem.rightBarButtonItem = rigthBarButtonItem
    }
    
    
    func fadeIn(){
        println("fadeIn")
        var rigthBarButtonItem = UIBarButtonItem(title: "淡出", style: UIBarButtonItemStyle.Bordered, target: self, action: "fadeOut")
        self.navigationItem.rightBarButtonItem = rigthBarButtonItem
        UIView.beginAnimations("fadeOut", context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval.abs(1.0))
        
        self.imageView_cat.alpha = 1.0
        
        UIView.commitAnimations()
    }

    func fadeOut(){
        println("fadeOut")
        var rigthBarButtonItem = UIBarButtonItem(title: "淡入", style: UIBarButtonItemStyle.Bordered, target: self, action: "fadeIn")
        self.navigationItem.rightBarButtonItem = rigthBarButtonItem
        //var context : CGContextRef = UIGraphicsGetCurrentContext()

        UIView.beginAnimations("fadeIn", context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(NSTimeInterval.abs(1.0))
        
        self.imageView_cat.alpha = 0.0
        
        UIView.commitAnimations()
        
        
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
